%%%----------------------------------------------------------------------
%%% File    : cus_ejabberd_c2s.erl
%%% Author  : chen.kangmin
%%%----------------------------------------------------------------------

-module(cus_sys_msg).
-author('chen.kangmin').


-include("logger.hrl").
-include("ejabberd.hrl").
-include("cus_pb.hrl").
-include("cus.hrl").


-export([new_message/5]).

-export([
    revoke_message/2,
    prompt/3,
    cornucopia_finish/4
        ]).



-define(SYS0001, "sys0001").                    %% 系统用户0001


revoke_message(Mid, Prompt) ->
    Cid = cus_util:get_cid_from_mid(Mid),
    Json = {obj,[{text, ?l2b(Prompt)}, {mid, ?l2b(Mid)}]},
    J = rfc4627:encode(Json),
    new_message(Cid, ?RM, ?SYS0001, J, "").


prompt(Cid, Text, Members) ->
    Json = {obj,[{text, ?l2b(Text)}]},
    J = rfc4627:encode(Json),
    new_message(Cid, ?SP, ?SYS0001, J, Members).


cornucopia_finish(Cid, Text, LotteryId, Members) ->
    Json = {obj,[{text, ?l2b(Text)}, {lotteryId, ?l2i(LotteryId)}]},
    J = rfc4627:encode(Json),
    new_message(Cid, ?CF, ?SYS0001, J, Members).


new_message(Cid, Type, Uid, Content, Members) ->
    #msg{mid = cus_util:uuid(),
         conversationid = Cid,
         msgtype = Type,
         fromuser = Uid,
         content = Content,
         msgstatus = "0",
         members = Members,
         msgtime = cus_util:utc_timestamp_str()}.
     